import { ComponentProps, Hook, VueComponent } from "vue3-oop"
import { NFormItem,NInputNumber } from 'naive-ui';
import NumberProps from './NumberProps'
import styles from './NumberView.module.scss'
import { WidgetNode } from '../../../types'

interface IProps {
  widgetNode: WidgetNode
}
export default class NumberView extends VueComponent<IProps> {
  static defaultProps: ComponentProps<IProps> = {
    widgetNode: {}
  }

  constructor() {
    super();
  }

  render(){
    const { widgetNode } = this.props;
    const widgetProps = widgetNode.widgetProps as NumberProps;

    const isRequired = widgetProps.layout_status==='4'

    const value = (widgetProps.field_default && widgetProps.field_default.trim().length>0 && !isNaN(widgetProps.field_default as any))
      ? Number(widgetProps.field_default) : null;

    return(
      <NFormItem
        label={widgetProps.field_label}
        labelPlacement="left"
        labelAlign={widgetProps.formitem_labelAlign}
        labelWidth={widgetProps.formitem_labelWidth}
      >
        <NInputNumber value={value}/>
      </NFormItem>
    )
  }
}